<?php
class Crypto extends Object
{
    public static function GetIV()
	{
	    if(extension_loaded('mcrypt') === false)
	    {
			return false;
	    }

		$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
    	return mcrypt_create_iv($iv_size, MCRYPT_RAND);
	}

    public static function Encrypt($data)
	{
		$iv = self::GetIV();
		if ($iv === false) return $data;

		return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, AppConfig::GetInstance()->MCRYPT_KEY, $data, MCRYPT_MODE_ECB, $iv));
	}

    public static function Decrypt($data)
	{
		$iv = self::GetIV();
		if ($iv === false) return $data;

		return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, AppConfig::GetInstance()->MCRYPT_KEY, base64_decode($data), MCRYPT_MODE_ECB, $iv));
	}
}
?>
